@extends('adminDialog')

@section('content')
    <form action="{{url('admin/product/updatet/'.$model->id)}}" method="POST" class="J_ajaxForm"
          style="height:  height: 599px;">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <div class="pop_cont pop_table" style="overflow-y: scroll;height: 500px;">
            <table width="100%">
                <tbody>

                <tr>
                    <th><label for="name">类别名称 <span class="red">*</span></label></th>
                    <td>
                        <input type="text" name="name" id="name" class="input length_6" value="{{$model->name}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="name_cn">中文名称</label></th>
                    <td>
                        <input type="text" name="name_cn" id="name_cn" class="input length_6" value="{{$model->name_cn}}"/>
                    </td>
                </tr>
                <tr>
                    <th><label for="parent_id">父级类别</label></th>
                    <td>
                        <select id="type_select" name="parent_id">
                            <option value="0" {{!isset($model->parent_id) || 0 == $model->parent_id ? 'selected="selected"' : ''}}>顶级分类</option>
                            @foreach($parents as $key=>$item)
                                <option value="{{$key}}" {{isset($model->parent_id) && $key == $model->parent_id ? 'selected="selected"' : ''}}>{{$item}}</option>
                            @endforeach
                        </select>
                        <select id="type_id" name="type_id" data-type_id="{{isset($appends['type_id']) ? $appends['type_id'] : ''}}" disabled style="display: none">

                        </select>
                        &nbsp;&nbsp;
                        <div id="sort" style="display: inline-block">排序：<input name="range" id="range" type="number" value="0"  style="width: 4em"/></div>
                    </td>
                </tr>

                <tr>
                    <th><label for="pic">类别主图</label></th>
                    <td><a href="javascript:;" id="pic" class="pic" title="选择上传文件">
                            <input type="hidden" name="pic" value="{{$model->pic}}"/>
                            @if(isset($model->pic) && 0 != $model->pic)
                                <p class="btn">选择上传文件</p>
                                <img src="/img/product-{{ $model->pic }}/243-165" style="margin-top: 10px;"/>
                            @else
                                <p class="btn">选择上传文件</p>
                                <img src="/img/product-{{ $model->pic }}12/243-165" style="display: none;margin-top: 10px;"/>
                            @endif
                        </a>
                    </td>
                </tr>
                <tr>
                    <th><label for="description">备注 </label></th>
                    <td>
                        <textarea name="description" id="description" style="width:350px; height: 50px;">
                            {{ $model->description }}
                        </textarea>
                    </td>
                </tr>
                <tr>
                    <th><label for="description_cn">中文备注 </label></th>
                    <td>
                        <textarea name="description_cn" id="description_cn" style="width:350px; height: 50px;">{{ $model->description_cn }}</textarea>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>

        <div class="pop_bottom cc">
            <button type="reset" class="btn fr" id="J_dialog_close">取消</button>
            <button type="submit" class="btn btn_submit J_ajax_submit_btn fr mr10" id="J_dialog_close">提交</button>
        </div>
    </form>
@stop

@section('style')
    <style>
        .body_none {
            width: 720px;
        }
    </style>
@stop

@section('js')
    @parent
    @include('UEditor::head')
    <script src="{{ asset('js/plupload/plupload.full.min.js') }}"></script>
    <script>
        var Select = {
            del: function (obj, e) {
                if ((e.keyCode || e.which || e.charCode) == 8) {
                    var opt = obj.options[0];
                    opt.text = opt.value = opt.value.substring(0, opt.value.length > 0 ? opt.value.length - 1 : 0);
                }
            },
            write: function (obj, e) {
                if ((e.keyCode || e.which || e.charCode) == 8)return;
                var opt = obj.options[0];
                opt.selected = "selected";
                opt.text = opt.value += String.fromCharCode(e.charCode || e.which || e.keyCode);
            }
        }
    </script>
    <script>
        $(function () {
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'client_pic', // you can pass in id...
                //container: document.getElementById('container'), // ... or DOM Element itself
                url: "{{ url('upimg') }}",
                filters: {
                    max_file_size: '5mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ]
                },
                multi_selection: false,
                file_data_name: 'file',
                multipart_params: {'_token': '{{ csrf_token() }}', 'dir': 'client'},
                // Flash settings
                flash_swf_url: '{{ asset("js/plupload/Moxie.swf") }}',
                // Silverlight settings
                silverlight_xap_url: '{{ asset('js/plupload/Moxie.xap') }}',
                init: {
                    PostInit: function () {
                        return false;
                    },
                    FilesAdded: function (up, file) {
                        $('.up-pic img').attr('src', '{{ asset('images/loading.gif') }}');
                        uploader.start();
                    },
                    Error: function (up, err) {
                        tips(err.message);
                    },
                    FileUploaded: function (up, file, responseObj) {
                        var response = $.parseJSON(responseObj.response);
                        //alert(response.state);
                        if (response.state == 'success') {
                            $('.client_pic img').attr('src', '{!! url("img/client-' + response.id + '/243-165") !!}');
                            $('.client_pic input').val(response.id);
                        } else {
                            tips(response.message);
                        }
                    }
                }
            });
            uploader.init();
        });
        $(function () {
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'pic', // you can pass in id...
                //container: document.getElementById('container'), // ... or DOM Element itself
                url: "{{ url('upimg') }}",
                filters: {
                    max_file_size: '5mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ]
                },
                multi_selection: false,
                file_data_name: 'file',
                multipart_params: {'_token': '{{ csrf_token() }}', 'dir': 'type'},
                // Flash settings
                flash_swf_url: '{{ asset("js/plupload/Moxie.swf") }}',
                // Silverlight settings
                silverlight_xap_url: '{{ asset('js/plupload/Moxie.xap') }}',
                init: {
                    PostInit: function () {
                        return false;
                    },
                    FilesAdded: function (up, file) {
                        $('.up-pic img').attr('src', '{{ asset('images/loading.gif') }}');
                        uploader.start();
                    },
                    Error: function (up, err) {
                        tips(err.message);
                    },
                    FileUploaded: function (up, file, responseObj) {
                        var response = $.parseJSON(responseObj.response);
                        //alert(response.state);
                        if (response.state == 'success') {
                            $('.pic img').css('display','block');
                            $('.pic img').attr('src', '{!! url("img/type-' + response.id + '/210-145") !!}');
                            $('.pic input').val(response.id);
                        } else {
                            tips(response.message);
                        }
                    }
                }
            });
            uploader.init();
        });

        $(function(){
            $("#type_select").on("change", function(){
                if("0" != $(this).val()){
                    $("div#sort").hide();
                }else{
                    $("div#sort").show();
                }
            });
        })
    </script>
@stop
